package org.llc.flink.study.example

object ClosureDemo01 {
  def main(args: Array[String]): Unit = {
    val fun = makeSuffix(".png")

    // dog.png
    println(fun("dog.png"))
    // cat.png
    println(fun("cat"))
  }

  /**
    *
    * @param suffix 传入
    * @return
    */
  def makeSuffix(suffix: String) = {
    // 返回一个匿名函数，会使用到suffix
    (filename: String) => {
      if (filename.endsWith(suffix)) {
        filename
      } else {
        filename + suffix
      }
    }
  }
}
